<template>
  <div class="dashboard-editor-container">
    <el-skeleton style="width: 100%" animated :loading="!showData" >
      <template slot="template">
        <el-row :gutter="20" style="width: 100%;" class="statistics-group">
            <el-col v-for="(item,index) in [1,2,3,4,5,6,7,8]" :key="index" :xs="12" :sm="12" :lg="6" class="statistics-panel-col">
              <el-skeleton-item variant="rect" style="width: 100%;height: 120px" />
            </el-col>
        </el-row>
      </template>
      <template>
        <el-card style="margin: 0 10px">
          <el-row style="width: 100%" type="flex" justify="center" align="middle">
            <span style="font-size: 18px;font-weight: bolder">今日填报情况</span>
            <router-link to="/count-enter/manager">
              <span class="home-subtitle">查看更多<i class="el-icon-d-arrow-right"/></span>
            </router-link>
          </el-row>
          <el-row :gutter="20" class="statistics-group" >
              <el-col v-for="(item, index) in totalData" :key="index" :xs="12" :sm="12" :lg="6" class="statistics-panel-col" @click.native="linkToMore">
                <div class="statistics-panel">
                  <div class="statistics-panel-icon-wrapper icon-lightning" v-if="device!=='mobile'">
                    <svg-icon :icon-class="svgMap[item.module_name]" class-name="statistics-panel-icon" />
                  </div>
                  <div class="statistics-panel-description">
                    <div class="statistics-panel-text">
                      {{item.module_name?item.module_name:'未知'}}
                    </div>
                    <div class="statistics-panel-num">
                      已填报(<count-to :start-val="0" :end-val="parseInt(item.actual_report_num)" class="actual-inputs" :duration="2600"/>)
                    </div>
                    <div class="statistics-panel-num">
                      应填报(<count-to :start-val="0" :end-val="parseInt(item.should_report_num)" class="should-inputs" :duration="2600"/>)
                    </div>
                  </div>
                </div>
              </el-col>
          </el-row>
        </el-card>
      </template>
    </el-skeleton>
    <div style="margin-bottom: 20px"></div>
    <el-skeleton style="width: 100%" :loading="!showChart" animated>
      <template slot="template">
        <el-row :gutter="20" style="width: 100%;height: 360px">
          <el-col class="chart-cell" :xs="24" :sm="12" v-for="(item,index) in tempTbData" :key="index">
            <el-skeleton-item variant="image" style="width: 100%; height: 300px;"/>
          </el-col>
        </el-row>
        <div style="margin-bottom: 30px"></div>
        <el-row :gutter="20" style="width: 100%;height: 360px">
          <el-col class="chart-cell" :xs="24" :sm="12" v-for="(item,index) in tempHbData" :key="index">
            <el-skeleton-item variant="image" style="width: 100%; height: 300px;"/>
          </el-col>
        </el-row>
      </template>
      <template>
        <el-row  style="width: 100%;height: 360px">
          <el-col class="chart-cell" :xs="24" :sm="12" v-for="(item,index) in tbData" :key="index">
            <el-card style="width: 100%">
              <line-bar-chart ref="tbChart" :chart-data="item" :line-color="lineColor" :bar-color="barColor" />
            </el-card>
          </el-col>
        </el-row>
        <el-row  style="width: 100%;height: 360px">
          <el-col class="chart-cell" :xs="24" :sm="12" v-for="(item,index) in hbData" :key="index">
            <el-card style="width: 100%">
              <line-bar-chart ref="hbChart" :chart-data="item" :line-color="lineColor" :bar-color="barColor" />
            </el-card>
          </el-col>
        </el-row>
        <div style="margin-bottom: 20px"></div>
      </template>
    </el-skeleton>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import CountTo from 'vue-count-to'
import LineBarChart from "@/views/bigdata/analysis/LineBarChart"
import analyApi from '@/api/analysis'
import homeApi from '@/api/article'

export default {
  name: 'DashboardAdmin',
  components:{
    CountTo,
    LineBarChart
  },
  computed:{
    ...mapGetters([
      'device'
    ])
  },
  data() {
    return {
      svgMap:{
        '垃圾量模块':'home-rubbish',
        '生产指标模块':'home-produce',
        '锅炉技术指标模块':'home-boiler',
        '汽轮机技术指标模块':'home-turbine',
        '环保耗材技术指标模块':'home-consume',
        '餐厨生产指标模块':'home-food',
        '收运指标模块':'home-transport',
        '化污水模块':'home-sewage',
      },
      lineColor:'#d5d730',
      barColor:'#1890ff',
      showData:false,
      currentTab:'today',
      totalTabList:[{name:'今天',key:'today'},{name:'昨天',key:'yesterday'}],
      totalData:[],
      showChart:false,
      tbData:null,
      hbData:null,
      tempTbData:[{name:'tb-c1'},{name:'tb-c2'}],
      tempHbData:[{name:'hb-c1'},{name:'hb-c2'}]
    }
  },
  created() {
    this.loadTotalData()
    this.loadChartData()
  },
  methods: {
    loadTotalData(){
      this.showData=false
      homeApi.homeSummary().then(res=>{
        this.totalData=res.data
        this.showData=true
      })
    },
    loadChartData() {
      this.showChart=false
      analyApi.analysisTbRatio({}).then(res=>{
        const dataArr =res.data
        this.tbData = this.convertChartData(dataArr)
        this.showChart=true
      })
      analyApi.analysisHbRatio({}).then(res=>{
        const dataArr = res.data
        this.hbData = this.convertChartData(dataArr,'环比')
        this.showChart=true
      })
    },
    convertChartData(dataArr,type='同比'){
      let chartsOpts = []
      for (let cdata of dataArr){
        let chartOpt = {
          names:[cdata.name,type],
          messures:[cdata.messure,'%'],
          xValues:Object.keys(cdata.data),
          yValues:[Object.values(cdata.data), Object.values(cdata.ratio)]
        }
        chartsOpts.push(chartOpt)
      }
      return chartsOpts
    },
    linkToMore(){
      this.$router.push('/count-enter/manager')
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 10px;
  /*background-color: rgb(240, 242, 245);*/
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  .chart-cell{
    padding: 0 10px;
    height: 350px;
  }

  .home-subtitle{
    position: absolute;
    top: 10px;
    right: 10px;
    cursor: pointer;
    font-size: 12px;
    color:#5a5e66;
    &:hover{
      text-decoration: #5a5e66 underline;
    }
  }

  .statistics-group {
    padding: 10px;
    margin-top: 10px;

    .el-col-lg-4-8 {
      width: 20%;
    }

    .statistics-panel-col {
      margin-bottom: 20px;
    }

    .statistics-panel {
      height: 120px;
      cursor: pointer;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      color: #666;
      background: #fff;
      border-radius: 10px;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
      border-color: rgba(0, 0, 0, .05);

      &:hover {
        .statistics-panel-icon-wrapper {
          color: #fff;
        }

        .icon-lightning {
          background: #1890ff;
        }

        .icon-rubbit {
          background: #d2e62f;
        }

        .icon-turbine {
          background:#34bfa3;
        }

        .icon-qushi {
          background: #62125e;
        }
        .icon-water{
          background: #36a3f7;
        }
      }

      .icon-lightning {
        color: #1890ff;
      }

      .icon-rubbit {
        color: #d2e62f;
      }

      .icon-turbine {
        color: #34bfa3;
      }

      .icon-qushi {
        color: #62125e;
      }
      .icon-water{
        color: #36a3f7;
      }

      .statistics-panel-icon-wrapper {
        /*float: left;*/
        /*margin: 10px 0 0 10px;*/
        position: absolute;
        top:16px;
        left: 16px;
        padding: 10px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }

      .statistics-panel-icon {
        float: left;
        font-size: 38px;
      }

      .statistics-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px 10px 26px 0;

        .statistics-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }

        .statistics-panel-num {
          margin-top: 5px;
          text-align: right;
          font-size: 15px;

          .actual-inputs{
            color: #4cd964;
          }
          .should-inputs{
            color: #1890ff;
          }

        }
      }
    }
  }

}
</style>
